export function test(){
  console.log("testtest");
}

function drawFrame(canvas,background,plane,turn){
  if(turn >= 2){
    return;
  }
  let vue = this;
  let ctx = canvas.getContext('2d');
  let t = 0;
  const transitionTime = 0.5,timeout = 30,
      totT = parseInt(Math.round(1000*transitionTime/timeout));
  let potName = "pot1"
  let startPot = this.GameInfo.Turns[turn][potName];
  let endPot = this.GameInfo.Turns[turn+1][potName]
  let deltaX = (endPot.pos.x - startPot.pos.x)/totT
  let deltaY = (endPot.pos.y - startPot.pos.y)/totT
  let deltaR = (endPot.rot - startPot.rot)/totT

  let interval = setInterval(function () {
    ctx.save();
    ctx.clearRect(0,0,canvas.width,canvas.height)
    ctx.drawImage(background,0,0,canvas.width,canvas.height)
    vue.drawPlane(ctx,plane,startPot.pos.x,startPot.pos.y,startPot.rot)
    startPot.pos.x += deltaX
    startPot.pos.y += deltaY
    startPot.rot += deltaR
    t++
    ctx.restore();
    if(t>=totT){
      clearInterval(interval)
      vue.drawFrame(canvas,background,plane,turn+1);
    }
  },timeout)
}
function drawPlane(ctx,plane,x,y,rot){
  ctx.save();
  const planeSize = 100;
  let center = this.getCenter(x,y,planeSize,planeSize)
  ctx.translate(center.x,center.y)
  ctx.rotate(rot)
  ctx.translate(-planeSize/2,-planeSize/2)
  ctx.drawImage(plane,0,0,planeSize,planeSize)
  ctx.restore();
}
function getCenter(sx, sy, width, height){ // 返回物体的中心点
  return {
    x: sx + (width / 2),
    y: sy + (height / 2)
  };
}